package com.ctcemti.mdm.project.sys.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.ctcemti.mdm.project.sys.entity.formdata.BaseReq;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.persistence.Id;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 登录日志对象 t_sys_login_log
 * 
 * @author 
 * @date Tue Nov 12 14:30:37 CST 2019
 */
@Data
@ApiModel("登录日志对象")
@JsonIgnoreProperties(value={"handler"})//是json序列化时忽略bean中的一些属性序列化和反序列化时抛出的异常.
public class LoginLog extends BaseReq implements Comparable<LoginLog>
{
    private static final long serialVersionUID = 1L;


    /**
    * id主键
    */
    @Id
    @ApiModelProperty(value = "id主键")
    private Long id;
    /**
    * 登录名
    */
    @Excel(name = "登录名")
    @NotNull(message = "登录名不能为空" )
    @ApiModelProperty(value = "登录名")
    private String loginName;
    /**
    * 登录类型
    */
    @Excel(name = "登录类型")
    @NotNull(message = "登录类型不能为空" )
    @ApiModelProperty(value = "登录类型")
    private int loginType;
    /**
    * 设备名称
    */
    @Excel(name = "设备名称")
    @NotNull(message = "设备名称不能为空" )
    @ApiModelProperty(value = "设备名称")
    private String deviceName;
    /**
    * ip地址
    */
    @Excel(name = "ip地址")
    @NotNull(message = "ip地址不能为空" )
    @ApiModelProperty(value = "ip地址")
    private String ipAdress;
    /**
    * 登录时间
    */
    @Excel(name = "登录时间")
    @NotNull(message = "登录时间不能为空" )
    @ApiModelProperty(value = "登录时间")
    private Date loginTime;


    @Transient
    @ApiModelProperty(hidden = true)//swagger忽略属性
    private int rowNum;

    @Transient
    @Excel(name = "错误提示")
    @ApiModelProperty(hidden = true)//swagger忽略属性
    private String errorMsg;

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("loginName", getLoginName())
            .append("loginType", getLoginType())
            .append("deviceName", getDeviceName())
            .append("ipAdress", getIpAdress())
            .append("loginTime", getLoginTime())
            .toString();
    }

    @Override
    public int compareTo(LoginLog loginLog) {           //重写Comparable接口的compareTo方法，
         return this.rowNum - loginLog.getRowNum();// 根据行号升序排列，降序修改相减顺序即可
    }

}
